<?php
namespace App\Http\Controllers\User\System;

use App\User\UserBaseModel;
use App\Http\Controllers\Controller;

use Yansongda\Pay\Exceptions\Exception;
use Yansongda\Pay\Pay;
use Illuminate\Http\Request;

class WxPayController extends Controller
{

    public function  pay(string $order_sn,$total_amount,string $subject)
    {
        $order      = [
            'out_trade_no' => $order_sn,
            'body' => $subject,
            'total_fee' => $total_amount*100, //单位：分
        ];
        try{
            $data = app('wechat_pay')->mp($order);
            $content        = $data->getContent();
        }catch (Exception $exception){
            return self::response($exception->raw,-5,'支付失败');
        }

        $content        = json_decode($content,true);
        if (empty($content)){
            $content    = new \stdClass();
        }

        return self::response(['param'=>$content]);
    }


    public function checkWxPay($xml_data)
    {
        $result =  Pay::wechat($this->config)->verify($xml_data);
        return $result;
    }

}
